package greddy;
public class _02_376摆动序列 {
    public static int wiggleMaxLength(int[] nums) {    	
    	int curDiff = 0;
    	int preDiff = 0;
    	int count = 1;
    	for(int i = 1; i < nums.length; i++) {
    		// 当前差值
    		curDiff = nums[i] - nums[i-1];
    		// 当前差值大于0 且 前一次的差值小于0，则是摆动值
    		// 这里的preDiff==0是因为初始状态是0，首次进行比较时才能通过
    		// 在经过初始状态的赋值后，由于curDiff>0的条件在，后面的preDiff不可能=0
    		if((curDiff > 0 && preDiff <= 0) || (curDiff < 0 && preDiff >= 0)) {
    			count++;
    			preDiff = curDiff;
    		}
    		
    	}
    	return count;
    }
    
    public static void main(String[] args) {
    	int[] nums = {33,53,12,64,50,41,45,21,97,35,47,92,39,0,93,55,40,46,69,42,6,95,51,68,72,9,32,84,34,64,6,2,26,98,3,43,30,60,3,68,82,9,97,19,27,98,99,4,30,96,37,9,78,43,64,4,65,30,84,90,87,64,18,50,60,1,40,32,48,50,76,100,57,29,63,53,46,57,93,98,42,80,82,9,41,55,69,84,82,79,30,79,18,97,67,23,52,38,74,15};
    	System.out.println(wiggleMaxLength(nums));
	}
}
